package Util;

/**
 *
 * @author Oanh
 */
public class CalculationWindown {

    public double wp;
    public double ws;
    public int N;
    public double wc;
    public double[] hn;
    public int max_hn = 0;
    public double[] hdn;
    public int min_hdn = 0;
    public int max_hdn = 0;
    public int wRN[];
    public double wTN[];
    public double wHanN[];
    public double wHamN[];
    public double wBlackN[];
    public double wKaiN[];

    public CalculationWindown(double wp, double ws, int N, int typeWindow) {
        this.wp = wp;
        this.ws = ws;
        this.N = N;

        double pi = Math.PI;
        wc = pi * (wp + ws) / 2;
        
       
        hn = new double[N];
        for (int i = 0; i <= N - 1; i++) {
            hn[i] = wc / pi * sin(wc * (i - (N - 1) / 2)) / (wc * (i - (N - 1) / 2));
            if (hn[i] > hn[max_hn]) {
                max_hn = i;
            }
        }
        hdn = new double[N];

        switch (typeWindow) {
            case 0:
                wRN = new int[N];
                for (int i = 0; i <= N - 1; i++) {
                    wRN[i] = 1;
                    hdn[i] = hn[i] * wRN[i];
                    if (hdn[i] < hdn[min_hdn]) {
                        min_hdn = i;
                    }
                    if (hdn[i] > hdn[max_hdn]) {
                        max_hdn = i;
                    }
                }
                break;
            case 1:
                wTN = new double[N];
                for (int i = 0; i <= (N - 1) / 2; i++) {
                    wTN[i] = 2 * i / (double) (N - 1);
                }
                for (int i = (N - 1) / 2; i <= N - 1; i++) {
                    wTN[i] = 2 - 2 * i / (double) (N - 1);
                }
                break;
            case 2:
                wHanN = new double[N];
                for (int i = 0; i <= N - 1; i++) {
                    wHanN[i] = 0.5 - 0.5 * cos(2 * pi / (N - 1) * i);
                }
                break;
            case 3:
                wHamN = new double[N];
                for (int i = 0; i <= N - 1; i++) {
                    wHamN[i] = 0.54 - 0.46 * cos(2 * pi / (N - 1) * i);
                }
                break;
            case 4:
                wBlackN = new double[N];
                for (int i = 0; i <= N - 1; i++) {
                    wBlackN[i] = 0.42 - 0.5 * cos(2 * pi / (N - 1) * i) + 0.08 * cos(4 * pi / (N - 1) * i);
                }
                break;
            case 5:
                wKaiN = new double[N];
                for (int i = 0; i <= N - 1; i++) {
                  
                }
                break;
        }
    }

    private double sin(double x) {
        return Math.sin(x);
    }

    private double cos(double x) {
        return Math.cos(x);
    }
}
